package com.tcsl.mylibrary;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 描述:支付类父类
 * <p/>作者：wjx
 * <p/>创建时间: 2017/5/26 16:30
 */
public abstract class TcslPay {
    protected String TAG = getClass().getSimpleName();
    protected OnPayListener mListener;
    protected Activity mActivity;
    protected Context mContext;
    protected String pkName;
    protected String timeStamp;

    public TcslPay(Context context) {
        mContext = context;
        try {
            PackageInfo info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
            pkName = info.packageName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        try {
            mActivity = (Activity) context;
        } catch (Exception e) {
            throw new IllegalArgumentException("the context must be activity");
        }
    }

    /**
     * @param money      支付金额 以元为单位
     * @param orderNo    订单号
     * @param merchantNo 商户号 盒子支付时使用
     * @param listener
     */
    public void pay(Float money, String orderNo, String merchantNo, OnPayListener listener) {
        this.mListener = listener;
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");
        timeStamp = format.format(new Date());
        pay(money, orderNo, merchantNo);
    }

    protected abstract void pay(Float money, String orderNo, String merchantNo);

    /**
     * 设备是否支持收银支付
     *
     * @return 是否支持刷银行卡
     */
    public static boolean isSupportPay() {
        int mEType = TCSLApplication.getInstance().getSystem().getEquipmentType();
        return mEType == Constants.HEZIZHIFU ||
                mEType == Constants.LKL ||
                mEType == Constants.WANGPOS ||
                mEType == Constants.MEITUAN ||
                mEType == Constants.UMS || mEType == Constants.CPOS
                || mEType == Constants.FEIPOS || mEType == Constants.MiniWang;
    }

    /**
     * 取消注册
     */
    public void unRegister() {
    }

    /**
     * 接收部分机具执行的打印返回码
     *
     * @param requestCode
     * @param resultCode
     * @param data
     * @return
     */
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        return false;
    }
}
